package net.sf.xoperator.ui.aiml;

import java.util.HashMap;
import java.util.Map;

import net.sf.xoperator.blackboard.NoPlanBlackBoardControl;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openbbs.blackboard.ks.KSExecutionContext;

import bitoflife.chatterbean.AliceBot;
import bitoflife.chatterbean.text.Request;

public class AliceBotExternal extends AliceBot {


	private Log log = LogFactory.getLog(AliceBotExternal.class);
	

	private Map<String, ExternalListener> externals = new HashMap<String, ExternalListener>();

	public void registerExternalListener(ExternalListener listener) {
		this.externals.put(listener.getName(), listener);
	}

	public void removeExternalListener(ExternalListener listener) {
		this.externals.remove(listener.getName());
	}

	public Map<String, ExternalListener> getExternalListeners() {
		return this.externals;
	}
	public ExternalListener getListener(String name) {
		return this.externals.get(name);
	}


	public String respond(String req, KSExecutionContext kscontext, NoPlanBlackBoardControl control) {
		BlackBoardContext bbcon  = (BlackBoardContext) getContext();
		bbcon.setContext(kscontext);
		bbcon.setControl(control);
		String res = super.respond(new Request(req)).trimOriginal();
		return res;


	}
	@Override
	public String respond(String req){
		throw new UnsupportedOperationException("Do not this method!");
	}


}
